package com.hhh.tools.ui.components

import android.widget.Toast
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun ConversationButton() {
    val context = LocalContext.current
    val openDialog = remember {
        mutableStateOf(false)
    }
    Button(
        onClick = {
            openDialog.value = true
            Toast.makeText(context, "button click", Toast.LENGTH_SHORT).show()
        },
        modifier = Modifier
            .padding(0.dp, 10.dp, 0.dp, 0.dp)
            .fillMaxWidth()
            .height(44.dp),
        shape = RoundedCornerShape(24.dp)
    ) {
        Text(text = "button")
    }

    ConversationDialog(openDialog)
}

@Composable
fun ConversationDialog(openDialog: MutableState<Boolean>) {
    if (openDialog.value) {
        AlertDialog(onDismissRequest = { openDialog.value = false }, title = {
            Text(text = "开启位置服务", fontWeight = FontWeight.W700, style = MaterialTheme.typography.h6)
        }, text = {
            Text(text = "这将意味着，我们会给您提供精准的位置服务，并且您将接受关于您订阅的位置信息", fontSize = 16.sp)
        }, confirmButton = {
            TextButton(onClick = { openDialog.value = false }) {
                Text(
                    text = "确认",
                    fontWeight = FontWeight.W700,
                    style = MaterialTheme.typography.button
                )
            }
        }, dismissButton = {
            TextButton(onClick = { openDialog.value = false }) {
                Text(
                    text = "取消",
                    fontWeight = FontWeight.W700,
                    style = MaterialTheme.typography.button
                )
            }
        })
    }
}